package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-05-24
 * Time: 17:08
 */
public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println();
        System.out.println("=====归还图书=====");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您要归还图书的书名：");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                if (book.isBorrowed() == false) {
                    System.out.println("该图书还未被借阅！！！");
                    System.out.println();
                    return;
                }
                book.setBorrowed(false);
                System.out.println("归还图书成功！！！");
                System.out.println();
                return;
            }
        }
        System.out.println("没有查找到该图书！！！");
        System.out.println();
    }
}
